﻿using System;

namespace ggdll.GGMessages.Outgoing
{
    class GGMessageLogin
    {
        private static int message_type=(int)GGMessageType.GG_LOGIN80;
        private int message_size;
        public int uin;
        public string language;
        public byte hash_type;
        public byte[] hash = new byte[64];
        public int status;
        public int flags;
        public int features;
        public int local_ip=0;
        public short local_port=0;
        public int external_ip=0;
        public short external_port=0;
        public byte image_size;
        public byte unknown1 = 0x64;
        public string version="";
        public string description = "";

        public byte[] getBytes()
        {
            message_size = 105 + version.Length + description.Length;
            byte[] response = new byte[message_size + 8];

            System.Buffer.BlockCopy(BitConverter.GetBytes(message_type), 0, response, 0, 4); // Header
            System.Buffer.BlockCopy(BitConverter.GetBytes(message_size), 0, response, 4, 4); // Header
            System.Buffer.BlockCopy(BitConverter.GetBytes(uin), 0, response, 8, 4); // uid
            System.Buffer.BlockCopy(StaticVars.enc.GetBytes(language), 0, response, 12, 2); //lang
            response[14] = 2; //SHA1
            System.Buffer.BlockCopy(hash, 0, response, 15, hash.Length);

            System.Buffer.BlockCopy(BitConverter.GetBytes(status), 0, response, 79, 4); //status
            System.Buffer.BlockCopy(BitConverter.GetBytes(flags), 0, response, 83, 4); //flagi
            System.Buffer.BlockCopy(BitConverter.GetBytes(features), 0, response, 87, 4); //feats

            System.Buffer.BlockCopy(BitConverter.GetBytes(local_ip), 0, response, 91, 4); //localIP
            System.Buffer.BlockCopy(BitConverter.GetBytes(local_port), 0, response, 95, 2); //localPort

            System.Buffer.BlockCopy(BitConverter.GetBytes(external_ip), 0, response, 97, 4); //remoteIP
            System.Buffer.BlockCopy(BitConverter.GetBytes(external_port), 0, response, 101, 2); //remotePort

            System.Buffer.BlockCopy(BitConverter.GetBytes(image_size), 0, response, 103, 1); //imagesize
            System.Buffer.BlockCopy(BitConverter.GetBytes(unknown1), 0, response, 104, 1); //unknown

            System.Buffer.BlockCopy(BitConverter.GetBytes(version.Length), 0, response, 105, 4); //versionLength
            System.Buffer.BlockCopy(StaticVars.enc.GetBytes(version), 0, response, 109, version.Length); //version

            System.Buffer.BlockCopy(BitConverter.GetBytes(description.Length), 0, response, 109 + version.Length, 4); //descLe
            System.Buffer.BlockCopy(StaticVars.enc.GetBytes(description), 0, response, 113 + version.Length, description.Length); //desc

            return response;
        }
    }

    
}
